<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * TicketWorkers_model
 * Build by Phuc Nguyen
 * Contact : nguyenvanphuc0626@gmail.com
 */

class TicketWorkers_model extends MY_Model{
    public function __construct(){
            parent::__construct();
            $this->table_name = 'book_ticketworkers';
    }
    
    public function updateCashBooking($params){
        $this->db->query("UPDATE {$this->table_name} SET `book_cash` = `book_cash` + 3000 WHERE id = {$params['id']}");
        return $this->db->affected_rows();
    }

    public function init_data($right){
		return array(
                               array(
						'name' => 'id',
						'label' => $this->lang->line('number'),
						'width' => '2%',
						'sort'  => FALSE,
						'searchoptions' => false
				),
                                array(
						'name' => 'name',
						'label' => $this->lang->line('name'),
						'width' => '10%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'status',
						'label' => $this->lang->line('status'),
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'lastupdated',
						'label' => $this->lang->line('lastupdated'),
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => false
				),
                                array(
						'name'  => 'button',
						'width' => '10%',
						'sort'  => FALSE,
						'label'  => $right['add']==TRUE?'<div class="btn-group">
						<a style="width: 82px;" href="'.site_url('auth/ticketWorkers/index/add').'" class="btn btn btn-success">'.$this->lang->line('create').'</a>
						</div>':'',
						'searchoptions' => false
				)
		);
	}
	
	public function json_data($controller, $right){
		$this->datatables
		->select("*")
		->from($this->table_name)
                ->where('status','1');
		//->unset_column('id');
	
		$this->datatables->set_produce_output(false);
		$ouput = $datatables = $this->datatables->generate();
		unset($ouput['aaData']);
		$ouput['aaData'] = array();

		foreach($datatables['aaData'] as $item){
			$ouput['aaData'][] = array(
                            $item['id'],
                            $item['name'],
                            ($item['status']==1)?$this->lang->line('active'):$this->lang->line('unactive'),                            
                            date("d-m-Y H:i:s",strtotime($item['lastupdated'])),
                            $this->add_button($controller, $right, $item)
			);
		}
	
		return json_encode($ouput);
	}
        
}